package com.queen.testretrofitrxjava.presenter;

import android.support.annotation.NonNull;

import com.queen.testretrofitrxjava.entity.MovieDetail;
import com.queen.testretrofitrxjava.http.HttpMethods;
import com.queen.testretrofitrxjava.httpSubscriber.ProgressSubscriber;
import com.queen.testretrofitrxjava.httpSubscriber.SubscriberOnNextListener;
import com.queen.testretrofitrxjava.presenter.presenterView.BasePresenterView;

import javax.inject.Inject;

/**
 * Created by liukun on 16/3/19.
 */
public class MovieDetailPresenter {

    private BasePresenterView movieDetailView;

    private HttpMethods httpMethods;

    private SubscriberOnNextListener<MovieDetail> onNextListener;

    @Inject
    public MovieDetailPresenter(HttpMethods httpMethods) {
        this.httpMethods = httpMethods;

        onNextListener = new SubscriberOnNextListener<MovieDetail>() {
            @Override
            public void onNext(MovieDetail movieDetail) {
                movieDetailView.renderView(movieDetail);
            }
        };
    }

    public void setView(@NonNull BasePresenterView movieDetailView){
        this.movieDetailView = movieDetailView;
    }

    public void requestMovieDetail(String movieId){

        httpMethods.getMovieDetail(new ProgressSubscriber(onNextListener), movieId);
    }

}
